import Page from '../../common/page';
import Dialog from '../../dist/dialog/dialog';
import Notify from '../../dist/notify/notify';

const app = getApp()
const request = require('../../utils/https.js')
import util from '../../utils/util.js';
var userId, totalPrice, fromUser, ranktotalPrice;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value: 1,
    editor: true,
    checkAll: false,
    totalCount: 0,
    totalPrice: (0).toFixed(2), //注册用户价格总价
    ranktotalPrice: (0).toFixed(2), //会员价格总价
    isHideToast: false,
    fixed: '',
    limitMax: false //数量购买限制
  },

  //编辑
  onEditor() {
    const that = this;
    //记录购物车选中的商品
    //编辑删除需要清空所有复选框 按钮改变 数量 总价 归0
    var goodsList = that.data.goodsList;
    var domCar = that.data.domCar;
    var domCar2 = that.data.domCar2;
    var oveCar = that.data.oveCar;
    var tjCar = that.data.tjCar;
    var nbCar = that.data.nbCar;
    var nbYbCar = that.data.nbYbCar;
    goodsList.forEach((v) => {
      v.checked = false;
    });

    domCar.forEach((v) => {
      v.checked = false;
    });
    domCar2.forEach((v) => {
      v.checked = false;
    });
    oveCar.forEach((v) => {
      v.checked = false;
    });
    tjCar.forEach((v) => {
      v.checked = false;
    });
    nbCar.forEach((v) => {
      v.checked = false;
    });
    nbYbCar.forEach((v) => {
      v.checked = false;
    });

    that.setData({
      editor: false,
      goodsList: goodsList,
      domCar: domCar, //国内池子
      domCar2: domCar2, //国内(代发货商家)
      oveCar: oveCar, //海外池子
      tjCar: tjCar, //天津
      nbCar: nbCar, //宁波
      nbYbCar: nbYbCar, //宁波一般
      checkAll: false,
      totalCount: 0,
      totalPrice: (0).toFixed(2),
      ranktotalPrice: (0).toFixed(2)
    })
  },
  //完成
  onComplete() {
    const that = this;
    var goodsList = that.data.goodsList;
    var domCar = that.data.domCar;
    var domCar2 = that.data.domCar2;
    var oveCar = that.data.oveCar;
    var tjCar = that.data.tjCar;
    var nbCar = that.data.nbCar;
    var nbYbCar = that.data.nbYbCar;
    goodsList.forEach((v) => {
      v.checked = false;
    });
    domCar.forEach((v) => {
      v.checked = false;
    });
    domCar2.forEach((v) => {
      v.checked = false;
    });
    oveCar.forEach((v) => {
      v.checked = false;
    });
    tjCar.forEach((v) => {
      v.checked = false;
    });
    nbCar.forEach((v) => {
      v.checked = false;
    });
    nbYbCar.forEach((v) => {
      v.checked = false;
    });

    that.setData({
      editor: true,
      goodsList: goodsList,
      domCar: domCar, //国内池子
      domCar2: domCar2, //国内(贷发货商家)
      oveCar: oveCar, //海外池子
      tjCar: tjCar, //天津
      nbCar: nbCar, //宁波
      nbYbCar: nbYbCar, //宁波一般贸易
      checkAll: false,
      totalCount: 0,
      totalPrice: (0).toFixed(2),
      ranktotalPrice: (0).toFixed(2)
    })
    //重新拉取购物车数据
  },
  /**
   * 用户选择购物车商品
   */
  checkboxChange: function (e) {

    console.log('点击购物车')

    const that = this;
    var deleteArr = [e.detail.value];
    var goodsList = that.data.goodsList;
    var values = e.detail.value;

    for (var i = 0; i < goodsList.length; ++i) {
      goodsList[i].checked = false;
      for (var j = 0; j < values.length; ++j) {
        if (goodsList[i].cartId == values[j]) {
          goodsList[i].checked = true;
          break;
        }
      }
    }


    //国内商品
    var domCar = that.data.domCar;
    for (var i = 0; i < domCar.length; ++i) {
      domCar[i].checked = false;
      for (var j = 0; j < values.length; ++j) {
        if (domCar[i].cartId == values[j]) {
          domCar[i].checked = true;
          break;
        }
      }
    }

    //国内(代发货商家)
    var domCar2 = that.data.domCar2;
    for (var i = 0; i < domCar2.length; ++i) {
      domCar2[i].checked = false;
      for (var j = 0; j < values.length; ++j) {
        if (domCar2[i].cartId == values[j]) {
          domCar2[i].checked = true;
          break;
        }
      }
    }

    //国外商品
    var oveCar = that.data.oveCar;
    for (var i = 0; i < oveCar.length; ++i) {
      oveCar[i].checked = false;
      for (var j = 0; j < values.length; ++j) {
        if (oveCar[i].cartId == values[j]) {
          oveCar[i].checked = true;
          break;
        }
      }
    }
    //天津池子
    var tjCar = that.data.tjCar;
    for (var i = 0; i < tjCar.length; ++i) {
      tjCar[i].checked = false;
      for (var j = 0; j < values.length; ++j) {
        if (tjCar[i].cartId == values[j]) {
          tjCar[i].checked = true;
          break;
        }
      }
    }
    //宁波池子
    var nbCar = that.data.nbCar;
    for (var i = 0; i < nbCar.length; ++i) {
      nbCar[i].checked = false;
      for (var j = 0; j < values.length; ++j) {
        if (nbCar[i].cartId == values[j]) {
          nbCar[i].checked = true;
          break;
        }
      }
    }
    //宁波一般
    var nbYbCar = that.data.nbYbCar;
    for (var i = 0; i < nbYbCar.length; ++i) {
      nbYbCar[i].checked = false;
      for (var j = 0; j < values.length; ++j) {
        if (nbYbCar[i].cartId == values[j]) {
          nbYbCar[i].checked = true;
          break;
        }
      }
    }


    var checkAll = false;
    if (goodsList.length == values.length) {
      checkAll = true;
    }

    that.setData({
      goodsList: goodsList,
      checkAll: checkAll,
      deleteArr: deleteArr,
      domCar: domCar, //国内池子
      domCar2: domCar2, //国内(代发货商家)
      oveCar: oveCar, //海外池子
      tjCar: tjCar, //天津
      nbCar: nbCar, //宁波
      nbYbCar: nbYbCar //宁波一般

    });
    that.calculateTotal();
  },

  /**
   * 用户点击全选
   */
  selectalltap: function (e) {
    const that = this;
    //点击全选 已经下架的库存不足的 商品不能选中
    var value = e.detail.value;
    var checkAll = false;
    if (value && value[0]) {
      checkAll = true;
    }
    var goodsList = that.data.goodsList;
    var deleteArr = [];
    if (e.detail.value[0] == 'true') {
      goodsList.forEach((v) => {
        deleteArr.push(v.cartId)
      });
    }

    for (var i = 0; i < goodsList.length; i++) {
      var good = goodsList[i];
      //下架的商品不可以去结算

      if (goodsList[i].enable != 1 && goodsList[i].has) { //没下架有库存才能去结算
        good['checked'] = checkAll;
      }
    }

    //国内商品
    var domCar = that.data.domCar;
    for (var i = 0; i < domCar.length; ++i) {

      if (domCar[i].enable != 1 && domCar[i].has) {
        domCar[i].checked = checkAll;
      }

    }
    //国内(代发货商家)
    var domCar2 = that.data.domCar2;
    for (var i = 0; i < domCar2.length; ++i) {

      if (domCar2[i].enable != 1 && domCar2[i].has) {
        domCar2[i].checked = checkAll;
      }

    }
    //国外商品
    var oveCar = that.data.oveCar;
    for (var i = 0; i < oveCar.length; ++i) {
      if (oveCar[i].enable != 1 && oveCar[i].has) {
        oveCar[i].checked = checkAll;
      }
    }
    //天津仓
    var tjCar = that.data.tjCar;
    for (var i = 0; i < tjCar.length; ++i) {
      if (tjCar[i].enable != 1 && tjCar[i].has) {
        tjCar[i].checked = checkAll;
      }
    }

    //宁波仓
    var nbCar = that.data.nbCar;
    for (var i = 0; i < nbCar.length; ++i) {
      if (nbCar[i].enable != 1 && nbCar[i].has) {
        nbCar[i].checked = checkAll;
      }
    }
    //宁波一般
    var nbYbCar = that.data.nbYbCar;
    for (var i = 0; i < nbYbCar.length; ++i) {
      if (nbYbCar[i].enable != 1 && nbYbCar[i].has) {
        nbYbCar[i].checked = checkAll;
      }
    }

    that.setData({
      checkAll: checkAll,
      goodsList: goodsList,
      deleteArr: deleteArr,
      domCar: domCar,
      domCar2: domCar2, //国内(代发货商家)
      oveCar: oveCar,
      tjCar: tjCar, //天津
      nbCar: nbCar, //宁波
      nbYbCar: nbYbCar //宁波一般
    });
    that.calculateTotal();
  },


  onLoad: function (options) {
    //this.getShopCarList(); //渲染购物车列表
    this.getDiscount(); //优惠等级
    userId = wx.getStorageSync('userId');

  },
  //优惠等级
  getDiscount() {
    const that = this;
    request._get(getApp().Api_url + 'cart/discount', { //优惠等级
      userId: wx.getStorageSync("userId")
    }, function (res) {
      console.log(res.data)
      if (res.data.errMsg == 'OK') {
        var disCount = res.data.data;
        console.log('优惠等级===>', disCount)
        that.setData({
          growthValue: disCount.growthValue,
          discountNum: disCount.discountNum * 10,
          outerDiscountNum: disCount.outerDiscountNum,
          outerMoney: disCount.outerMoney,
          rankMoney: disCount.rankMoney,
          isTop: disCount.isTop
        })
      }
    }, function () {})
  },

  //购物车商品列表渲染
  getShopCarList() {
    const that = this;
    request._get(getApp().Api_url + 'cart/mine', { //商品类别接口
      userId: wx.getStorageSync("userId"),
      pageNum: 1,
      pageSize: 100
    }, function (res) {
      if (res.data.code == 200) {
        var goodsList = res.data.data;
        var totalCount = 0;
        for (var i = 0; i < goodsList.length; i++) {
          var good = goodsList[i];
          totalCount += good.prodNum;
        }
        if (totalCount > 0) {
          //购物车数量接口
          wx.setTabBarBadge({
            index: 3,
            text: totalCount.toString()
          })
        } else {
          wx.removeTabBarBadge({
            index: 3
          })
        }

        goodsList.forEach((v) => {
          if (v.checked == 0) {
            v.checked = false;

          } else {
            v.checked = true;
          }
        });


        let domCar = []; //国内购物车池
        let domCar2 = []; //国内(代发货商家)
        let oveCar = []; //国外购物车池
        let tjCar = []; //天津
        let nbCar = []; //宁波
        let nbYbCar = []; //宁波一般贸易仓

        goodsList.forEach((v) => {
          if (v.inOrOut == 0) { //国内仓发货
            if (v.tradeNum == '004') { //商家代发货
              domCar2.push(v)
            } else if (v.tradeNum == '005') { //宁波一般贸易仓
              nbYbCar.push(v)
            } else { //国内(天津)一般贸易
              domCar.push(v)
            }
          }
          if (v.inOrOut == 1) { //海外发货
            oveCar.push(v)
          }
          if (v.tradeNum == '002') { //天津跨境
            tjCar.push(v)
          }
          if (v.tradeNum == '003') { //宁波跨境
            nbCar.push(v)
          }
        })


        that.setData({
          goodsList: goodsList, //全部商品
          domCar: domCar,
          domCar2: domCar2,
          oveCar: oveCar,
          tjCar: tjCar,
          nbCar: nbCar,
          nbYbCar: nbYbCar
        })
      }
    }, function () {})
  },
  //删除单条商品
  onClose(event) {
    const that = this;
    var itemid = event.currentTarget.dataset.itemid;
    const {
      position,
      instance
    } = event.detail;
    switch (position) {
      case 'left':
      case 'cell':
        instance.close();
        break;
      case 'right':
        Dialog.confirm({
          message: '确定删除吗？'
        }).then(() => {
          instance.close();
          //请求删除接口
          let deleteArr = [];
          deleteArr.push(itemid);
          that.onDelete(deleteArr, that);


        });
        break;
    }
  },

  //批量删除商品
  onDeletes() {
    const that = this;
    var deleteArr = that.data.deleteArr;
    that.onDelete(deleteArr, that);
  },

  //删除商品
  onDelete(deleteArr, that) {
    request._post(getApp().Api_url + 'cart/delCart', {
      userId: wx.getStorageSync("userId"),
      cartIdArr: deleteArr

    }, function (res) {
      if (res.data.errMsg == 'OK') {
        //添加购物车成功
        //根据接口返回是否添加成功 成功提醒

        Notify({
          duration: 1000,
          text: '删除成功~',
          selector: '#custom-selector',
          backgroundColor: '#e92f2e',
          safeAreaInsetTop: true
        });
        that.getShopCarList();
      }
    }, function () {})
  },
  goShopping1() {
    wx.switchTab({
      url: '/pages/list/list',
    })
  },

  //结算
  getOrder() {
    const that = this;

    userId = wx.getStorageSync("userId");
    if (userId == '' || userId == null || userId == 'undefined') {
      wx.navigateTo({
        url: '/pages/login/login?path=/pages/shopping_car/shopping_car'
      })
      return;
    }
    //检查 购物车每一件商品等于true的
    var checkedgoods = that.data.goodsList.filter(item => {
      return item.checked;
    })
    if (checkedgoods.length == 0) {
      wx.showToast({
        title: '请选择商品',
        icon: 'none'
      })
      return false;
    }


    var inventoryNumer = true; //库存量变量开关 true 足 false 不足
    checkedgoods.forEach((v) => {
      if (v.number < v.prodNum && v.number != 0) { //检查库存和选中的数量大小
        wx.showToast({
          title: '库存不足，请重新选择',
          icon: 'none'
        })
        console.log('库存不足===>')
        inventoryNumer = false;
      }
    })

    if (inventoryNumer) {
      var goodsDomestic = []; //国内
      var goodsDomestic2 = []; //国内2
      var goodsForeign = []; //国外
      var goodsTj = []; //天津
      var goodsNb = []; //宁波
      var goodsNbYb = []; //宁波一般
      //商品分类结算
      checkedgoods.forEach((v) => {
        if (v.inOrOut == 0) {
          //国内
          if (v.tradeNum == '004') {
            goodsDomestic2.push(v)
          } else if (v.tradeNum == '005') {
            goodsNbYb.push(v)
          } else {
            goodsDomestic.push(v)
          }

        } else if (v.inOrOut == 1) {
          goodsForeign.push(v)
          //国外
        } else if (v.inOrOut == 2) {
          //跨境
          if (v.tradeNum == '002') {
            goodsTj.push(v)
          }
          if (v.tradeNum == '003') {
            goodsNb.push(v)
          }
        }
      })
      if (goodsForeign.length == checkedgoods.length || goodsDomestic.length == checkedgoods.length || goodsDomestic2.length == checkedgoods.length || goodsTj.length == checkedgoods.length || goodsNb.length == checkedgoods.length || goodsNbYb.length == checkedgoods.length) {
        console.log('直接购买')
        //不出现弹框的情况是 全是 国内12 或者全是国外 商品
        that.setData({
          showShopp: false,
          fixed: ''
        })
        var totalprice = 0;
        var inOrOut;
        checkedgoods.forEach((v) => {
          totalprice += v.currentPrice * v.prodNum;
          if (v.inOrOut == 0) {
            //国内
            inOrOut = 0;
          } else if (v.inOrOut == 1) {
            //国外
            inOrOut = 1;
          } else if (v.inOrOut == 2) {
            //跨境
            inOrOut = 2;

          }
        })

        let typeArr = []; //未去重的品类
        let buyMax; //最大购买数量
        let typeMax; //最大购买品类数
        let totalNum = 0 //总购买商品数
        checkedgoods.forEach((v) => { //计算价格，
          buyMax = v.max;
          typeMax = v.typeMax;
          console.log(v.prodNum);
          totalNum += v.prodNum*v.innerProds;
          v.innerSkus.forEach((v) => {
            typeArr.push(v)
          })
        })

        console.log('totalNum==>',totalNum)

        let TypeArrlength = new Set(typeArr).size; //去重后的后的品类数
        //buyMax>0 TypeArrlength的种类数不超过typeMax 购买的数量totalNum不能超过buyMax
        if (buyMax > 0) {
          if (TypeArrlength > typeMax || buyMax < totalNum) { //弹框
            that.setData({
              limitMax: true,
              fixed: 'fixed',
              buyMax,
              typeMax,
              TypeArrlength,
              totalNum

            })
            return false;
          }
        }

        wx.setStorageSync('goods', JSON.stringify(checkedgoods));
        wx.setStorageSync('totalprice', totalprice);
        wx.navigateTo({
          url: '/pages/order1/order1?type=' + 1 + '&inOrOut=' + inOrOut + '&link=shopp' //购物车
        })
        that.setData({
          showShopp: false,
          fixed: ''
        })
      } else {
        console.log('弹框购买')
        that.setData({
          goodsForeign: goodsForeign,
          goodsDomestic: goodsDomestic,
          goodsDomestic2: goodsDomestic2,
          goodsTj: goodsTj,
          goodsNb: goodsNb,
          goodsNbYb: goodsNbYb,
          showShopp: true,
          fixed: 'fixed'
        })
      }
    }

  },
  //结算弹框
  goOrder() {
    const that = this;
    var totalprice = 0;
    console.log('that.data.radio1===>', that.data.radio1)

    if (!that.data.radio1) {
      wx.showToast({
        title: '请选择商品',
        icon: 'none'
      })
      return false;
    }

    if (that.data.radio1 == 0) { //国内仓
      var checkedgoods = that.data.goodsDomestic;
      var inOrOut = 0;
    } else if (that.data.radio1 == 1) { //国外
      var checkedgoods = that.data.goodsForeign;
      var inOrOut = 1;
    } else if (that.data.radio1 == 2) { //宁波一般
      var checkedgoods = that.data.goodsNbYb;
      var inOrOut = 0;
    } else if (that.data.radio1 == 3) { //天津保税
      var checkedgoods = that.data.goodsTj;
      var inOrOut = 2;
    } else if (that.data.radio1 == 4) { //宁波保税
      var checkedgoods = that.data.goodsNb;
      var inOrOut = 2;
    } else if (that.data.radio1 == 5) { //国内自营仓发货
      var checkedgoods = that.data.goodsDomestic2;
      var inOrOut = 0;
    }
    let typeArr = []; //未去重的品类
    let buyMax; //最大购买数量
    let typeMax; //最大购买品类数
    let totalNum = 0 //总购买商品数
    checkedgoods.forEach((v) => { //计算价格，
      totalprice += v.currentPrice * v.prodNum
      buyMax = v.max;
      typeMax = v.typeMax;
      console.log(v.prodNum);
      totalNum += v.prodNum*v.innerProds;
      v.innerSkus.forEach((v) => {
        typeArr.push(v)
      })
    })

    let TypeArrlength = new Set(typeArr).size; //去重后的后的品类数
    //buyMax>0 TypeArrlength的种类数不超过typeMax 购买的数量totalNum不能超过buyMax
    if (buyMax > 0) {
      if (TypeArrlength > typeMax || buyMax < totalNum) { //弹框
        /* wx.showToast({
          title: '超过购买数量',
          duration: 2000,
          icon: 'none'
        }) */
        that.setData({
          limitMax: true,
          fixed: 'fixed',
          buyMax,
          typeMax,
          TypeArrlength,
          totalNum

        })
        return false;
      }

    }



    wx.setStorageSync('goods', JSON.stringify(checkedgoods));
    wx.setStorageSync('totalprice', totalprice);

    wx.navigateTo({
      url: '/pages/order1/order1?type=' + 1 + '&inOrOut=' + inOrOut + '&link=shopp' //购物车
    })
    that.setData({
      showShopp: false,
      fixed: ''
    })
  },
  //返回购物车
  backShopping() {
    const that = this;
    that.setData({
      showShopp: false,
      fixed: ''
    })
  },
  //选择商品类型结算
  onChange1(event) {
    const {
      key
    } = event.currentTarget.dataset;
    this.setData({
      [key]: event.detail
    });
  },

  /**
   * 监听商品数量变化
   **/
  onChange(e) {
    const that = this;
    var index = e.target.dataset.index;
    var itemId = e.target.dataset.itemid;
    var goodsList = that.data.goodsList;
    var numbers = goodsList[index].prodNum;
    var totalCount = 0;
    goodsList[index].prodNum = e.detail;
    that.setData({
      goodsList: goodsList
    });


    /* for (var i = 0; i < goodsList.length; i++) {
      var good = goodsList[i];
      console.log('good.prodNum==>', good.prodNum)
      totalCount += good.prodNum;
    }
    if (totalCount > 0) {
      //购物车数量接口
      wx.setTabBarBadge({
        index: 3,
        text: totalCount.toString()
      })
    } else {
      wx.removeTabBarBadge({
        index: 3
      })
    } */


    that.calculateTotal();

    //回传每一个商品的的数量
    request._get(getApp().Api_url + 'cart/addOrSub', {
      count: e.detail,
      cartId: itemId,
      userId: wx.getStorageSync("userId"),
      what: 0

    }, function (res) {
      that.goodsNum();
    }, function () {})

  },

  /**
   * 计算商品总数
   */
  calculateTotal: function () {

    const that = this;
    var goodsList = that.data.goodsList;
    var totalCount = 0;
    var totalPrice = 0;
    var ranktotalPrice = 0;

    for (var i = 0; i < goodsList.length; i++) {
      var good = goodsList[i];
      if (good.checked) {
        totalCount += good.prodNum;

        if (good.oneValue) { //一口价
          totalPrice += good.prodNum * good.currentPrice;
          ranktotalPrice += good.prodNum * good.currentPrice;
        } else {
          totalPrice += good.prodNum * good.currentPrice;
          if(good.rankPrice!=null){
            ranktotalPrice += good.prodNum * good.rankPrice;
          } else {
            ranktotalPrice += good.prodNum * good.currentPrice;
          }
        }
      }



    }
    totalPrice = totalPrice.toFixed(2);
    ranktotalPrice = ranktotalPrice.toFixed(2);

    //区分 都是会员价/都是注册用户价/会员价+一口价/注册用户价+一口价


    that.setData({
      totalCount: totalCount,
      totalPrice: totalPrice,
      ranktotalPrice: ranktotalPrice
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getShopCarList();
    this.recommended();
    this.goodsNum();
    this.setData({
      checkAll: false,
      totalCount: 0,
      totalPrice: (0).toFixed(2),
      ranktotalPrice: (0).toFixed(2)
    })

    let userId = wx.getStorageSync("userId");
    if (userId == '' || userId == null || userId == 'undefined') {
      wx.reLaunch({
        url: '/pages/login/login?path=/pages/shopping_car/shopping_car'
      })
      return;
    }

    /* let userId = wx.getStorageSync("userId");
    if (userId == '' || userId == null || userId == 'undefined') {
      wx.navigateTo({
        url: '/pages/login/login',
      })
    } */
  },

  //购物车右上角icon
  goodsNum() {
    const that = this;
    //购物车数量
    request._get(getApp().Api_url + 'cart/mine', { //商品类别接口
      userId: wx.getStorageSync("userId"),
      pageNum: 1,
      pageSize: 100
    }, function (res) {
      if (res.data.errMsg == 'OK') {
        var goodsList = res.data.data;
        var totalCount = 0;
        for (var i = 0; i < goodsList.length; i++) {
          var good = goodsList[i];
          totalCount += good.prodNum;
        }
        if (totalCount > 0) {
          //购物车数量接口
          wx.setTabBarBadge({
            index: 3,
            text: totalCount.toString()
          })
        } else {
          wx.removeTabBarBadge({
            index: 3
          })
        }
      }
    }, function () {})
  },




  //为你推荐
  recommended() {
    const that = this;
    let userId = wx.getStorageSync('userId');
    //商品列表
    request._get(getApp().Api_url + 'cart/recommend', { //商品列表接口
      userId: userId,
      pageNum: 1,
      pageSize: 100
    }, function (res) {
      if (res.data.errMsg == 'OK') {
        var goodsList = res.data.data;
        that.setData({
          regoodsList: goodsList
        })

      }
    }, function () {})
  },
  //查看详情页
  goDetails(e) {
    const that = this;

    let userId = wx.getStorageSync("userId");
    if (userId == '' || userId == null || userId == 'undefined') {
      wx.reLaunch({
        url: '/pages/login/login?path=/pages/list/list'
      })
      return;
    }
    let goodsId = e.currentTarget.dataset.goodsid;
    let fast = e.currentTarget.dataset.fast;
    console.log('fast类型==>', typeof (fast))
    /*     let userId = wx.getStorageSync("userId");
         if (userId == '' || userId == null || userId == 'undefined') {
          wx.navigateTo({
            url: '/pages/login/login',
          })
          return;
        } */
    wx.navigateTo({
      url: '/pages/gift_details/gift_details?goodsId=' + goodsId + '&show=' + 0 + '&userId=' + fromUser + '&fast=' + fast
    })
  },
  //详情页拉起购物车
  goShopping(e) {
    const that = this;
    let userId = wx.getStorageSync("userId");
    if (userId == '' || userId == null || userId == 'undefined') {
      wx.reLaunch({
        url: '/pages/login/login?path=/pages/list/list'
      })
      return;
    }
    let goodsId = e.currentTarget.dataset.goodsid;
    let fast = e.currentTarget.dataset.fast;

    /*     let userId = wx.getStorageSync("userId");
        if (userId == '' || userId == null || userId == 'undefined') {
          wx.navigateTo({
            url: '/pages/login/login',
          })
          return;
        } */

    wx.navigateTo({
      url: '/pages/gift_details/gift_details?goodsId=' + goodsId + '&show=' + 1 + '&userId=' + fromUser + '&fast=' + fast
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.setData({
      editor: true,
    })
  },
  shutToast() {
    this.setData({
      limitMax: false,
      showShopp: false,
      fixed: '',
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})